package com.cloud.sysmana.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.cloud.util.other.StringUtil;

/**
 * 时间截取标签
 * 
 * @version 1.0
 * @date 2016-03-31
 * @author gaof
 */
@SuppressWarnings("serial")
public class DateSubStringTag extends TagSupport {

	/* 日期 */
	private String date;
	/* 截取长度 */
	private int subNum;
	/* 截取起始位置 */
	private int startIndex;


	/** 时间截取 */
	public int doStartTag() throws JspException {

		String dateNormal = "";
		if (startIndex > 0) {
			dateNormal = StringUtil.substring(date, startIndex, subNum);
		}else{
			dateNormal = StringUtil.substring(date, 0, subNum);
		}
		
		try {
			pageContext.getOut().print(dateNormal);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return super.doStartTag();

	}

	/* ========== get/set ========== */
	public int getSubNum() {
		return subNum;
	}

	public void setSubNum(int subNum) {
		this.subNum = subNum;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

}
